<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>评论列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="/layui-admin/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="/layui-admin/css/font_eolqem241z66flxr.css" media="all" />
	<link rel="stylesheet" href="/layui-admin/css/news.css" media="all" />
	<script src="/js/jquery-1.9.0.min.js"></script>
	<link rel="stylesheet" href="/layui-admin/css/simpleAlert.css">
	<script src="/layui-admin/js/simpleAlert.js"></script>
	<link rel="stylesheet" href="/layui-admin/css/jquery.pagination.css" />
	<script src="/layui-admin/js/jquery.pagination.min.js"></script>
	<style>
		* {
			margin: 0;
			padding: 0;
		}

		body {
			font-family: "微软雅黑";
			background: #eee;
		}

		button {
			display: inline-block;
			padding: 6px 12px;
			font-weight: 400;
			line-height: 1.42857143;
			text-align: center;
			vertical-align: middle;
			cursor: pointer;
			border: 1px solid transparent;
			border-radius: 4px;
			border-color: #28a4c9;
			color: #fff;
			background-color: #5bc0de;
			margin: 20px 20px 0 0;
		}

		.box {
			width: 800px;
			margin: 100px auto 0;
			height: 34px;
		}

		.page {
			width: 600px;
		}

		.info {
			width: 200px;
			height: 34px;
			line-height: 34px;
		}

		.fl {
			float: left;
		}
	</style>
	<script type="text/javascript">
        $(document).ready(function(){
            get_comments(1,10);
        });
        function get_comments(pageNum,pageSize) {
            $("#book_comments").html("");
            //弹出loading
            var index = top.layer.msg('数据加载中，请稍候',{icon: 16,time:false,shade:0.8});
            setTimeout(function(){
                top.layer.close(index);
                layer.closeAll("iframe");
            },1500);
            $.get("http://localhost:8080/get_comments_by_page?pageNum="+pageNum+"&pageSize="+pageSize,function(result){
                var data = eval(result);
                var html = "";
                var total =data.obj.pages;
                $.each(data.obj.list,function (indexs,values) {
                    html += "<tr>";
                    html +=     "<td hidden>" + values.commentId + "</td>"
                    html +=     "<td>" + Number(Number(indexs) + Number(1)) + "</td>"
                    html +=     "<td>" + values.book.bookName + "</td>"
                    html +=     "<td>" + values.include + "</td>"
                    html +=     "<td>" + values.dateTime + "</td>"
                    html +=     "<td>" + values.score + "</td>"
                    html +=     "<td>" + values.user.nickname + "</td>"
                    html +=     "<td>" + "<div id='"+values.commentId+"' style='width: 50%;float:left; display:inline;cursor:pointer;' class='layui-icon'onclick='del_comments(this.id)'>&#xe640;</div>" + "</td>"
                    html += "</tr>";
                });
                $("#book_comments").html(html);
                //执行一个laypage实例
                $("#pagination").pagination({
                    currentPage: 1,
                    totalPage:total ,
                    isShow: false,
                    prevPageText: "< 上一页",
                    nextPageText: "下一页 >",
                    callback: function(current) {
                        get_comments(current,10);
                    }
                });
            })
        }
        function del_comments(commentId){
            var comment = new FormData();
            comment.append("commentId", commentId);
            var dblChoseAlert = simpleAlert({
                "content":"您确定要删除这条评论吗？",
                "buttons":{
                    "确定删除":function () {
                        $.ajax({
                            url: "http://localhost:8080/del_comment",
                            data:comment,
                            type: "post",
                            dataType: "json",
                            cache: false,//上传文件无需缓存
                            processData: false,//用于对data参数进行序列化处理 这里必须false
                            contentType: false, //必须
                            success: function (res) {
                                get_comments(1,10);
                                layer.msg("图书删除成功")
                                dblChoseAlert.close();
                            },
                            error: function () {
                                get_books(1,10)
                                layer.msg("网络发生错误了")
                                dblChoseAlert.close();
                            },
                            beforeSend:function(){
                                //弹出loading
                                var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
                                setTimeout(function(){
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    dblChoseAlert.close();
                                },1500);
                            }
                        });
                    },
                    "容我想想":function () {
                        dblChoseAlert.close();
                    }
                }
            })
		}
	</script>
</head>
<body class="childrenBody">
	<!--<blockquote class="layui-elem-quote news_search">-->
		<!--<div class="layui-inline">-->
		    <!--<div class="layui-input-inline">-->
		    	<!--<input type="text" value="" placeholder="请输入关键字" class="layui-input search_input">-->
		    <!--</div>-->
		    <!--<a class="layui-btn search_btn">查询</a>-->
		<!--</div>-->
	<!--</blockquote>-->
	<div class="layui-form links_list">
	  	<table class="layui-table">
		    <colgroup>
				<col width="50">
				<col width="30%">
				<col>
				<col>
				<col>
				<col>
				<col>
				<col width="13%">
		    </colgroup>
		    <thead>
				<tr>
					<th hidden></th>
					<th>编号</th>
					<th style="text-align:left;">图书名称</th>
					<th>评论内容</th>
					<th>评论时间</th>
					<th>评论分数</th>
					<th>评论用户</th>
					<th>操作</th>
				</tr> 
		    </thead>
		    <tbody class="comments_list" id="book_comments"></tbody>
		</table>
		<div class="box">
			<div id="pagination" class="page fl"></div>
			<!--<div class="info fl">-->
				<!--<p>当前页数：<span id="current">1</span></p>-->
			<!--</div>-->
		</div>
	</div>
	<div id="page"></div>
	<script type="text/javascript" src="/layui-admin/layui/layui.js"></script>
	<script type="text/javascript" src="linksList.js"></script>
</body>
</html>